<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/3/6
 * Time: 9:47
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Other extends Base
{
    /**
     * 用户注册协议
     * @return mixed|\think\response\Json
     */
    public function registAgreement(){
        if(Request::instance()->isPost()){
            $agreement = input('agreement');
            $res = Db::table('up_other')
                ->where('other_id', 1)
                ->update(['other_regist' => $agreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_other')->where('other_id', 1)->value('other_regist');
        $this->assign('agreement', $agreement);
        return $this->fetch('other/registagreement');
    }
    
    /**
     * 联系客服
     * @return mixed|\think\response\Json
     */
    public function service(){
        if(Request::instance()->isPost()){
            $other_phone = input('other_phone');
            $other_qrcode_link = input('other_qrcode_link');
            $update['other_phone'] = $other_phone;
            if(!empty($other_qrcode_link)){
                $update['other_qrcode_link'] = $other_qrcode_link;
            }
            $res = Db::table('up_other')
                ->where('other_id', 2)
                ->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $service = Db::table('up_other')
            ->field('other_phone, other_qrcode_link')
            ->where('other_id', 2)
            ->find();
        $this->assign('service', $service);
        return $this->fetch();
    }
    
    /**
     * 用户协议
     * @return mixed|\think\response\Json
     */
    public function userAgreement(){
        if(Request::instance()->isPost()){
            $agreement = input('agreement');
            $res = Db::table('up_other')
                ->where('other_id', 3)
                ->update(['other_user_agreement' => $agreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_other')->where('other_id', 3)->value('other_user_agreement');
        $this->assign('agreement', $agreement);
        return $this->fetch('other/useragreement');
    }
    
    /**
     * 隐私协议
     * @return mixed|\think\response\Json
     */
    public function ysAgreement(){
        if(Request::instance()->isPost()){
            $agreement = input('agreement');
            $res = Db::table('up_other')
                ->where('other_id', 4)
                ->update(['other_ys_agreement' => $agreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_other')->where('other_id', 4)->value('other_ys_agreement');
        $this->assign('agreement', $agreement);
        return $this->fetch('other/ysagreement');
    }
    
    /**
     * 提现比例
     * @return mixed|\think\response\Json
     */
    public function txProp(){
        if(Request::instance()->isPost()){
            $tx_prop = input('other_tx_prop');
            $res = Db::table('up_other')
                ->where('other_id', 6)
                ->update(['other_tx_prop' => $tx_prop]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $prop = Db::table('up_other')->where('other_id', 6)->value('other_tx_prop');
        $this->assign('other_tx_prop', $prop);
        return $this->fetch('other/txprop');
    }
    
    /**
     * 充值比例
     * @return mixed|\think\response\Json
     */
    public function rechargeProp(){
        if(Request::instance()->isPost()){
            $recharge_prop = input('other_recharge_prop');
            $res = Db::table('up_other')
                ->where('other_id', 7)
                ->update(['other_recharge_prop' => $recharge_prop]);
            if($res){
                return json(['code' => 200, 'msg' =>'保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $prop = Db::table('up_other')->where('other_id', 7)->value('other_recharge_prop');
        $this->assign('other_recharge_prop', $prop);
        return $this->fetch('other/rechargeProp');
    }
    /**
     * 俱乐部发放金币
     * @return mixed|\think\response\Json
     */
    public function gold(){
        if(Request::instance()->isPost()){
            $recharge_prop = input('other_gold');
            $res = Db::table('up_other')
                ->where('other_id', 8)
                ->update(['other_gold' => $recharge_prop]);
            if($res){
                return json(['code' => 200, 'msg' =>'保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $prop = Db::table('up_other')->where('other_id', 8)->value('other_gold');
        $this->assign('other_gold', $prop);
        return $this->fetch('other/gold');
    }

    /**
     * 俱乐部发放金币
     * @return mixed|\think\response\Json
     */
    public function price(){
        if(Request::instance()->isPost()){
            $recharge_prop = input('other_gold');
            $res = Db::table('up_other')
                ->where('other_id', 9)
                ->update(['other_price' => $recharge_prop]);
            if($res){
                return json(['code' => 200, 'msg' =>'保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $prop = Db::table('up_other')->where('other_id', 9)->value('other_price');
        $this->assign('other_price', $prop);
        return $this->fetch('other/price');
    }

    /**
     * 俱乐部发放金币
     * @return mixed|\think\response\Json
     */
    public function coin(){
        if(Request::instance()->isPost()){
            $recharge_prop = input('other_gold');
            $res = Db::table('up_other')
                ->where('other_id', 10)
                ->update(['coin' => $recharge_prop]);
            if($res){
                return json(['code' => 200, 'msg' =>'保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $prop = Db::table('up_other')->where('other_id', 10)->value('coin');
        $this->assign('prop', $prop);
        return $this->fetch('other/coin');
    }

    //会员充值名额
    public function quota(){
        if(Request::instance()->isPost()){
            $recharge_prop = input('other_gold');
            $res = Db::table('up_other')
                ->where('other_id', 11)
                ->update(['quota' => $recharge_prop]);
            if($res){
                return json(['code' => 200, 'msg' =>'保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $prop = Db::table('up_other')->where('other_id', 11)->value('quota');
        $this->assign('prop', $prop);
        return $this->fetch('other/quota');
    }
}